package com.fanghaoran.view.user.notebookFrame;

import com.fanghaoran.controller.InfoController;
import com.fanghaoran.controller.WordController;
import com.fanghaoran.entity.Users;
import com.fanghaoran.entity.Words;
import com.fanghaoran.view.LoginFrame;

import javax.swing.*;
import java.awt.*;
import java.util.List;

/**
 * @Author: win11
 * @Date: 2023/03/27/21:51
 * @Description:
 */
public class NoteBookPanel extends JPanel {

    private final JTable table;

    /**
     * 用户的个人信息
     */
    private final Users user=(Users)new InfoController().getInfo(LoginFrame.usernameInput).getMessage();

    public NoteBookPanel() throws Exception {
        this.setLayout(new BorderLayout());
        //展示信息的表格
        //数据库获取该用户生词本数据
        @SuppressWarnings("unchecked")
        List<Words> wordList = (List<Words>) new WordController().getDataOfNoteBook(user.getId()).getMessage();
        table = new JTable(new NoteBookTableModel(wordList));
        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
        //放在panel中间位置
        this.add(new JScrollPane(table), BorderLayout.CENTER);
    }
}
